package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.SuperiorInfo
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IRequestLicenceView
import de.baumann.browser.model.UserModel
import de.baumann.browser.rx.RxSchedulers

class RequestLicencePresenter : BasePresenter<IRequestLicenceView>() {

    private val userModel = UserModel()

    fun inviteAndPoolInfo() {
        this.userModel.inviteAndPoolInfo()
                .subscribe(object : OdinObserver<SuperiorInfo>(view) {
                    override fun onSuccess(data: SuperiorInfo?) {
                        if (view != null && data != null) {
                            view.setInviteTip(data.invTip)
                            view.setInviteAvatar(data.invAvatar)
                            view.setInvitePhone(data.invPhone)

                            view.setPoolTip(data.poolTip)
                            view.setPoolAvatar(data.poolAvatar)
                            view.setPoolPhone(data.poolPhone)
                        }
                    }
                })
    }


    fun requestLicence(poolPhone: String, invitePhone: String,token:String) {
        userModel.requestLicence("$poolPhone,$invitePhone",token)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.requestSuccess()
                    }
                })
    }
}